<html>
<script>

    // function defineClass(
    //     constructor,                // 用以设置实例的属性的函数
    //     methods,                  // 实例的方法，复制至原型中
    //     statics                   // 类属性，复制至构造函数
    // ) {
    //     if (methods)  extend(constructor.prototype,methods) ;
    //     if (statics)  extend(constructor, statics); 
    //     return constructor;
    // }

    // 这是Range类的另一个实现
    var SimpeRange =
        defineClass(function (f, t) { this.f = f; this.t = t },
            {
                includes: function (x) { return this.f <= x && x <= this.t; },
                toString: function () { return this.f + "..." + this.t }
            },
            { upto: function (t) { return new SimpleRange(0, t); } }
        );

    function Complex(real, imaginary) {
        if (isNaN(real) || isNaN(imaginary)) {
            throw new TypeError();
        }
        this.r = real;
        this.i = imaginary;
    }
    // 当前负数对象加上另外一个负数, 并返回一个新的计算器和值后的复数对象
    Complex.prototype.add = function (that) {
        return new Complex(this.r + that.r, this.i + that.i);
    };

    // 当前复数乘以另外一个负数，并返回一个新的计算乘积的复数对象
    Complex.prototype.mul = function (that) {
        return new Complex(this.r * that.r - this.i * that.i, this.r * that.i + this.i * that.r);

    }

    // 计算的复数的模， 复数的模定为原点（0，0）到平面的距离
    Complex.prototype.mag = function () {
        return Math.sqrt(this.r * this.r + this.i * this.i);
    };

    // 复数的求负数运算
    Complex.prototype.neg = function () {
        return new Complex(-this.r, -this.i);
    };


    // 将复数对象转化为一个字符串
    Complex.prototype.toString = function () {
        return "{" + this.r + "," + this.i + "}";
    }

    // 检测当前复数是否和另外一个复数值相等
    Complex.prototype.equals = function (that) {
        return that != null &&
            that.constutor === Complex &&
            this.r === that.r && this.i === that.i;
    };

    Complex.ZERO = new Complex(0, 0);
    Complex.ONE = new Complex(1, 0);
    Complex.I = new Complex(0, 1);

    Complex.parse = function (s) {
        try {
            var m = Complex._format.exec(s);  // 利用正则表达式进行匹配
            return new Complex(parseFloat(m[1]), parseFloat(m[2]));
        } catch (error) {
            throw new TypeError("Can't parse'" + s + "'as a complex number'");
        }
    }



    // instanceof运算符号
    // instanceof 可以检查某个实例是否是某个构造函数生成的，由于他是用原型来检查，
    // 所以它百分百正确
    // instanceof操作的伪代码如下
    function instanceof_of(L, R) {
        var o = R.prototype;
        var o = L.proto;
        while (true) {
            if (L === null) { return false; }  // 该实力是用于Object.create(null)构造出来的，没有原型
            if (L === o) { return true }       // R在L的原型链
        }
    }

    function Person(name) {
        if(this instanceof Person) {
            console.log("call with new");
            this.name = name;
        } else {
            console.log("call without new");
            return new Person(name);
        }
    }

</script>


<head>
    <title>放置文章标题</title>
</head>

<body>

</body>

</html>